package com.lovo.pz.util;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 文件操作类
 * @author 白德柯
 *
 */
public class FileUtil {
    public static final String PATH = "user.dat";
    public static List read(){
        ObjectInputStream ois = null;
        List list = new ArrayList();
        try {
            ois = new ObjectInputStream(new FileInputStream(PATH));
            list = (List) ois.readObject();
        } catch (IOException | ClassNotFoundException e) {}
        finally {
            if(ois != null){
                try {
                    ois.close();
                } catch (IOException e) {}
            }
        }
        return list;
    }
    public static void write(List list){
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream(PATH));
            oos.writeObject(list);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(oos != null){
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
